using System.IO;

namespace AssemblyInfoPlugin
{
    public class AsmInfoVersion
    {
        private string _filename;
        
        public AsmInfoVersion(string filename)
        {
            this._filename = filename;
        }

        public string GetVersion(string separator) 
        {
            StreamReader sr = File.OpenText(this._filename);
            string info = sr.ReadToEnd();
            sr.Close();
            string token = "AssemblyVersion";
            int idx = info.IndexOf(token);
            idx = idx + token.Length;
            if(idx > -1)
            {
                int endIdx = info.IndexOf(")", idx);
                if(endIdx > -1)
                {
                    return info.Substring(idx, endIdx - idx).Replace("\"", "").Replace("(", "").Replace(".*", "").Replace(".", separator).Trim();
                }
            }
            return "";
        }
    }
}
